package com.oig.sys.base.dao;

import com.oig.sys.base.entity.TbEnumItem;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
@author wuxl
*/
public interface ITbEnumItemDao extends JpaRepository<TbEnumItem, Integer> {

	TbEnumItem getTbEnumItemById(Integer id);

	@Query("from TbEnumItem e where e.itemCode=:itemCode and e.dictId=:dictId")
	TbEnumItem getByItemCodeAndDictId(@Param("itemCode") String itemCode, @Param("dictId") Integer dictId);


	@Query("from TbEnumItem e where e.itemCode=:itemCode and e.dictId=:dictId and e.id<>:id")
	TbEnumItem getByCodeExtId(@Param("itemCode") String itemCode, @Param("dictId") Integer dictId, @Param("id")Integer id);


	@Query("from TbEnumItem e where e.dictId=:dictId")
	List<TbEnumItem> findByDictId(@Param("dictId") Integer dictId);

	@Query("from TbEnumItem e " +
			" where e.dictId=:dictId and e.status=:status " +
			" and (e.itemCode like :searchKey or e.itemName like :searchKey) " )
	List<TbEnumItem> searchByNameOrCode(@Param("dictId") Integer dictId, @Param("searchKey") String searchKey, @Param("status") String status);


	@Query("select e.id from TbEnumItem e where e.modifyFlag='0' and e.id not in(:idList) and e.dictId=:dictId")
	List<Integer> findAllCanNotDelId(@Param("dictId") Integer dictId, @Param("idList") List<Integer> idList);

	@Query("from TbEnumItem e where e.id not in(:idList) and e.dictId=:dictId")
	List<TbEnumItem> findByDictIdAnIdNotIn(@Param("dictId") Integer dictId, @Param("idList") List<Integer> idList);


}
